<?php
/**
 *
 *
 *
 */
namespace Yz\modules\Users;
use Yz_String;
class Item_Default
    extends \Yz_Item_Abstract
{


    /*************************
     *      Public methods   *
     *************************/

    /**
     *  @param string
     *  @return this
     *  @throw Yz_User_Exception
     */
    public function verifyPassword($password)
    {
        $password = Yz_String::testNotEmpty($password);
        if ( ! $this->matchPassword($password) )
            throw new \Yz_User_Exception();
        return $this;
    }

    /**
     *  @param string
     *  @return this
     */
    public function setPassword($password)
    {
        $password = Yz_String::testNotEmpty($password);
        $this->__dict__['passwordMD5'] = md5($password);
        return $this;
    }


    /**
     *
     */
    protected function matchPassword($password)
    {
        return md5($password) === $this->__dict__['passwordMD5'];
    }

} // class
